//
//  CLTabPagerBar.h
//  Charles
//
//  Created by Leo on 2019/4/25.
//  Copyright © 2019 charles. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "CLTabPagerBarLayout.h"

NS_ASSUME_NONNULL_BEGIN
@class CLTabPagerBar;
@protocol CLTabPagerBarDataSource <NSObject>

@required
// PagerTabBar 中元素数量
- (NSInteger)numberOfItemsInPagerTabBar;
// 设置PagerTabBar 元素Cell
- (UICollectionViewCell<CLTabPagerBarCellProtocol> *)pagerTabBar:(CLTabPagerBar *)pagerTabBar cellForItemAtIndex:(NSInteger)index;

@end

@protocol CLTabPagerBarDelegate <NSObject>

@optional
// 设置layout
- (void)pagerTabBar:(CLTabPagerBar *)pagerTabBar configureLayout:(CLTabPagerBarLayout *)layout;
// 如果Cell 的宽度不可变，你可以设置layout.cellWidth属性。否则，可以实现这个方法返回cell width。 cell width 不包含 cell edge。
- (CGFloat)pagerTabBar:(CLTabPagerBar *)pagerTabBar widthForItemAtIndex:(NSInteger)index;
// did select cell item
- (void)pagerTabBar:(CLTabPagerBar *)pagerTabBar didSelectItemAtIndex:(NSInteger)index;
// transition from cell to cell with animated
- (void)pagerTabBar:(CLTabPagerBar *)pagerTabBar transitionFromCell:(UICollectionViewCell<CLTabPagerBarCellProtocol> *_Nullable)fromCell toCell:(UICollectionViewCell<CLTabPagerBarCellProtocol> *_Nullable)toCell animated:(BOOL)animated;
// transition from cell to cell with progress
- (void)pagerTabBar:(CLTabPagerBar *)pagerTabBar transitionFromCell:(UICollectionViewCell<CLTabPagerBarCellProtocol> *_Nullable)fromCell toCell:(UICollectionViewCell<CLTabPagerBarCellProtocol> *_Nullable)toCell progress:(CGFloat)progress;

@end
/**
 分段页面Bar
 */
@interface CLTabPagerBar : UIView
// TabPagerBar 容器
@property (nonatomic, weak, readonly) UICollectionView *collectionView;
// 进度条
@property (nonatomic, strong) UIView *progressView;
// 背景
@property (nonatomic, strong) UIView *backgroundView;
// delegate
@property (nonatomic, weak, nullable) id<CLTabPagerBarDelegate> delegate;
// 数据源
@property (nonatomic, weak, nullable) id<CLTabPagerBarDataSource> dataSource;
// 样式布局
@property (nonatomic, strong) CLTabPagerBarLayout *layout;
// 是否自动滚动到中间 default: YES
@property (nonatomic, assign) BOOL autoScrollItemToCenter;
// 元素总数
@property (nonatomic, assign, readonly) NSInteger countOfItems;
// 当前选中item 索引
@property (nonatomic, assign, readonly) NSInteger curIndex;
// 内容偏移
@property (nonatomic, assign) UIEdgeInsets contentInset;

- (void)registerClass:(Class)Class forCellWithReuseIdentifier:(nonnull NSString *)identifier;
- (void)registerNib:(UINib *)nib forCellWithReuseIdentifier:(nonnull NSString *)identifier;
- (__kindof UICollectionViewCell<CLTabPagerBarCellProtocol> *)dequeueReusableCellWithReuseIdentifier:(NSString *)identifer forInex:(NSInteger)index;
- (void)reloadData;

- (void)scrollToItemFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex animated:(BOOL)animated;
- (void)scrollToItemFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress;
- (void)scrollToItemAtIndex:(NSInteger)index atScrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated;

- (CGFloat)cellWidthForTitle:(NSString *_Nullable)title;
- (CGRect)cellFrameWithIndex:(NSInteger)index;
- (nullable UICollectionViewCell<CLTabPagerBarCellProtocol> *)cellForIndex:(NSInteger)index;

@end

NS_ASSUME_NONNULL_END
